const utils = {
  toast(title = '数据加载失败...') {
    wx.showToast({
      title: title,
      mask: true,
      icon: 'none',
    })
  },
  formatDate(timestamp) {
    const date = new Date(timestamp)
    const year = date.getFullYear()
    const month = date.getMonth() + 1
    const day = date.getDate()

    return [year, month, day].map(this.formatNumber).join('/')
  },

  formatNumber(n) {
    n = n.toString()
    return n[1] ? n : `0${n}`
  },
}

wx.utils = utils

export default utils
